package indi.imooc.algorithm.conversion;

/**
 * 二进制转换
 */
public class BinaryConversion {

    public static int decimalToBinary(int n){
        int t = 0; // 二进制位数
        int r = 0; // 余数
        int res = 0;
        while (n != 0){
            r = n % 2;
            n /= 2;
            res += (int) (r * Math.pow(10,t));
            t++;
        }
        System.out.println(res);
        return res;
    }

    public static String  decimalToBinaryStr(int n){
        String str = "";
        while (n != 0){
            str = n % 2 + str;
            n /= 2;
        }
        System.out.println(str);
        return str;
    }
}
